package com.stylefeng.guns.modular.prof.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Prof;
import com.stylefeng.guns.modular.prof.service.IProfService;

/**
 * 会议专家控制器
 *
 * @author fengshuonan
 * @Date 2018-07-28 13:10:56
 */
@Controller
@RequestMapping("/prof")
public class ProfController extends BaseController {

    private String PREFIX = "/prof/prof/";

    @Autowired
    private IProfService profService;

    /**
     * 跳转到会议专家首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "prof.html";
    }

    /**
     * 跳转到添加会议专家
     */
    @RequestMapping("/prof_add")
    public String profAdd() {
        return PREFIX + "prof_add.html";
    }

    /**
     * 跳转到修改会议专家
     */
    @RequestMapping("/prof_update/{profId}")
    public String profUpdate(@PathVariable Integer profId, Model model) {
        Prof prof = profService.selectById(profId);
        model.addAttribute("item",prof);
        LogObjectHolder.me().set(prof);
        return PREFIX + "prof_edit.html";
    }

    /**
     * 获取会议专家列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return profService.selectList(null);
    }

    /**
     * 新增会议专家
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Prof prof) {
        profService.insert(prof);
        return SUCCESS_TIP;
    }

    /**
     * 删除会议专家
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer profId) {
        profService.deleteById(profId);
        return SUCCESS_TIP;
    }

    /**
     * 修改会议专家
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Prof prof) {
        profService.updateById(prof);
        return SUCCESS_TIP;
    }

    /**
     * 会议专家详情
     */
    @RequestMapping(value = "/detail/{profId}")
    @ResponseBody
    public Object detail(@PathVariable("profId") Integer profId) {
        return profService.selectById(profId);
    }
}
